package zhieasy.cn.common.strategy;

import com.github.zouchanglin.storage.service.upload.result.ReturnBody;
import com.google.common.collect.Maps;
import org.springframework.stereotype.Component;
import zhieasy.cn.common.utils.ResultVOUtil;
import zhieasy.cn.common.vo.ResultVO;

import java.io.InputStream;
import java.util.Map;
import java.util.Random;
import java.util.UUID;

/**
 * @author Dahang
 */
@Component
public class InitiationPolicy extends QiNiuObjectUpload implements UploadStrategy {

    @Override
    public String uploadOneFile(InputStream inputStream, String objectName) {
        // 路劲前加/book_market/
        String key = "/initiation/" + UUID.randomUUID();
        ReturnBody returnBody = qiNiuUploadService.uploadStream(inputStream, key, null);
        // TODO returnBody..
        return objectUrl + key;
    }

    @Override
    public ResultVO getTokenAndUrl() {
        String token = qiNiuAuthService.getToken();
        String key = "/initiation/" + new Random().nextInt(50) + "/";
        Map<String, String> retMap = Maps.newHashMap();
        retMap.put("token", token);
        retMap.put("key", key);
        return ResultVOUtil.success(retMap);
    }

    @Override
    public ResultVO getTokenAndUrl(String parentId) {
        return null;
    }
}
